<html>

<head>
    <title>关键物料更换-精工云MES系统移动端</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link href="/JG/Content/jquery/weui/style/weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/jquery/jquery-weui/css/jquery-weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/JG/Content/css/Global.css" rel="stylesheet" />
    <link rel="stylesheet" href="/JG/Content/css/ComponentsReplacement.css">
    <link rel="stylesheet" href="/JG/Content/css/TabletsGlobal.css?v=1">
    <script src="/JG/Content/LocalConfigs.js"></script>
    <script src="/JG/Content/LocalUserInfo.js"></script>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body ontouchstart>
    <!--title部分-->
    <header class="header">
        <div class="empty">
            <span id="stations"></span>
        </div>
        <div class="header_title">
            <a href="javascript:;">关键物料更换</a>
        </div>
        <div class="item item2">
            <div class="set">
                <span><img style="width:50px" src="/JG/Content/images/early.png" alt=""></span>
            </div>
            <div class="user_img" onclick="javascript:location.href='/JG/Home/Index.html'">
                <span class="back"><img src="/JG/Content/images/return.png" alt=""></span>
            </div>
            <div class="clean"></div>
        </div>
    </header>

    <div id="MainPage" class="MainPage" v-cloak>
        <div class="input-group" style="text-align:center;font-size:18px;">
            <label class="input-group-addon" for="BarCode">SN码</label>
            <input type="text" class="form-control" maxlength="50" v-model="BarCode" placeholder="扫描或输入SN码回车"
                id="BarCode" />
        </div>
        <div id="tab2" class="weui-tab__bd-item">
            <div class="left">
                <ul class="list-group">
                    <li class="list-group-item">当前SN码&nbsp;&nbsp;{{CurrBarCode}}
                    </li>
                    <li class="list-group-item">
                        产品SN码&nbsp; &nbsp;{{FormData.InvBarCode}}
                    </li>
                    <li class="list-group-item">
                        任务单号&nbsp;&nbsp;{{FormData.TaskCode}}
                    </li>
                    <li class="list-group-item">
                        产品名称&nbsp; &nbsp;{{FormData.InvName}} {{FormData.InvCode}}
                    </li>
                    <li class="list-group-item">
                        产品型号&nbsp; &nbsp;{{FormData.InvStd}}
                    </li>
                    <li class="list-group-item">
                        订单号码/内部订单号&nbsp;&nbsp;{{FormData.OrderCode}}/{{FormData.ProcessCode}}
                    </li>
                    <li class="list-group-item">
                        订单数量/任务数量&nbsp;&nbsp;{{FormData.OrderNum}}/{{FormData.TaskQty}}
                    </li>
                    <li class="list-group-item" v-if="CurrProcessIndex>1">
                        投入数量&nbsp;&nbsp;{{FormData.InputQty}}
                    </li>
                </ul>
            </div>

            <div class="right panel panel-default">
                <ul class="nav nav-tabs">
                    <li class="active">
                        <a href="#OperateRecord" data-toggle="tab">操作记录</a>
                    </li>
                    <!-- <li>
                        <a href="#Swiper" data-toggle="tab">操作指导</a>
                    </li> -->
                </ul>
                <div class="tab-content tabs">
                    <div class="tab-pane fade in active" id="OperateRecord">
                        <ul style="height:100%;overflow-y:auto;">
                            <li style="font-size: 1.2em" v-for="(item,index) in OperateRecord"
                                :style="{'color':item.Status?'blue':'red'}">
                                {{item.Content}}
                            </li>
                        </ul>
                    </div>
                    <div class="tab-pane fade" id="Swiper">
                        <div class="swiper-container">
                            <div class="swiper-wrapper" id="Top_Swiper">
                            </div>
                            <div class="swiper-pagination"></div>
                        </div>
                    </div>
                </div>
            </div>

            <!--弹窗部分-->
            <div class="dialog">
                <span><img src="/JG/Content/images/timg.jpg" alt="关闭"></span>
                <div class="dialog_img"><img src="" id="ShowImg" alt=""></div>
            </div>

            <div class="panel panel-default col-md-12 col-lg-12 col-sm-12" style="margin-top: 25px">
                <div class="panel-heading panel-heading1">
                    现关键物料
                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>物料条码</th>
                            <th>物料编码</th>
                            <th>物料名称</th>

                            <th style="text-align:center">通过状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(item,index) in ComponentBindData">
                            <td>{{index+1}}</td>
                            <td>{{item.newBarCode}}</td>
                            <td>{{item.InvCode}}</td>
                            <td>{{item.InvName}}</td>

                            <!-- <td style="text-align:center">
                                <span style="color:green;font-size: 18px" class="glyphicon glyphicon-ok"></span>
                            </td> -->
                            <td style="text-align:center"><span v-if="item.BindStatus"
                                    style="color:green;font-size: 18px" class="glyphicon glyphicon-ok"></span><span
                                    v-if="item.BindStatus==false" style="color:red;font-size: 18px"
                                    class="glyphicon glyphicon-remove"></span></td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="panel panel-default col-md-12 col-lg-12 col-sm-12" style="margin-top: 25px">
                <div class="panel-heading panel-heading1">
                    原关键物料
                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>物料条码</th>
                            <th>物料编码</th>
                            <th>物料名称</th>

                            <th style="text-align:center">通过状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(item,index) in ComponentBindData">
                            <td>{{index+1}}</td>
                            <td>{{item.oldBarCode}}</td>
                            <td>{{item.InvCode}}</td>
                            <td>{{item.InvName}}</td>

                            <td style="text-align:center">
                                <span style="color:red;font-size: 18px" class="glyphicon glyphicon-remove"></span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    </div>

    <script src="/JG/Content/jquery/jquery-3.2.1.min.js"></script>
    <script src="/JG/Content/jquery/jquery-weui/js/jquery-weui.min.js"></script>
    <script src="/JG/Content/Utils.js?v=1"></script>
    <script src="/JG//Content/AudioUtils.js"></script>
    <script src="/JG/Content/Common.js"></script>
    <script src="/JG//Content/Station.js"></script>
    <script src="/JG/Content/bootstrap.min.js"></script>
    <script src="/JG/Content/jquery/jquery-weui/js/swiper.min.js"></script>
    <script src="/JG/Content/jquery/fastclick.js"></script>
    <script src="/JG/Content/bootstrap/bootbox/bootbox.min.js"></script>
    <script src="/JG/Content/bootstrap/bootbox/bootbox.locales.min.js"></script>
    <script>
        $(function () {
            FastClick.attach(document.body);
            //安灯弹窗部分动态加载
            Station.Init(".header");
            var stations = LocalUserInfo.GetUserInfo();
            $("#stations").html(stations.ProductionLineName + " - " + stations.StationName);
        });
        //操作指导部分图片弹窗部分
        // function popup(e) {
        //     //debugger;
        //     //弹出背景

        //     //关闭文字字体大小
        //     // $(".dialog>span").css({
        //     //     'position': 'absolute',
        //     //     'right': '.3em',
        //     //     'font-size':'5em',



        //     // })
        //     $("#ShowImg")[0].src = e.src;
        //     $(".dialog").fadeIn();

        //     $(".dialog>span").click(function () {
        //         $(".dialog").fadeOut();
        //     })
        // }
    </script>
    <script src="/JG/Content/vue-v2.34.js"></script>
    <script type="text/javascript">
        var vmPage = new Vue({
            el: "#MainPage",
            data: {
                CurrProcessType: "GXLX004", //当前工序类型
                CurrProcessCode: "",  //当前工序编码
                CurrProcessName: "",  //当前工序名称
                CurrProcessIndex: 0,   //当前工序顺序
                ScanCodeNum: 0,        //扫码数量
                CurrBarCode: "",       //当前条码
                BarCode: "",
                IsDisable: false,
                FormData: {
                    ScheduleID: "", //排产单ID
                    TaskCode: "",   //任务号
                    TaskQty: "", //任务数量
                    InputQty: 0, //投入数量
                    InvCode: "",
                    InvName: "",
                    InvStd: "",
                    InvBarCode: "",
                    InvProcessType: "", //产品工序类型
                    InvSNRule: "", //条码验证规则
                    OrderCode: "",//订单号码
                    OrderNum: "",//订单数量
                    ProcessCode: "",//流程卡号
                },
                ComponentData: [], //物料数据
                ComponentBindData: [],//物料绑定数据
                StationRecord: [],//过站记录
                OperateRecord: [],//操作记录
                IsEmptyObj: false,//产品数据是不是空对象
                IsOldComponent: false,//旧物料是否已经扫描
                OddComponentBindData: [],//原关键物料
                NewComponentBindData: [],//现关键物料
                OddComponentBarcode: "",//旧物料条码
                NewComponentRules: "",//新物料验证规则
                bgsjzbId: "",//新物料验证规则
                MaxOperatingRecordNum: "",//操作记录显示最大条数
            },
            mounted: function () {
                var currSelf = this;
                $("#BarCode").focus();
                $("#BarCode").bind("keypress", currSelf.Enter);
                Utils.AutoBarCodeFocus();
                var data = MaxOperatingRecord();
                if (data.IsSuccess && data.Data) {
                    currSelf.MaxOperatingRecordNum = data.Data;
                }
            },
            methods: {
                SetOperateRecord: function (content, status) {
                    var currSelf = this;
                    var content = (new Date().Format("hh:mm:sss")) + ' ' + content;
                    currSelf.OperateRecord.splice(0, 0, { Content: content, Status: status });
                    if (currSelf.OperateRecord.length > currSelf.MaxOperatingRecordNum) {
                        currSelf.OperateRecord.splice(currSelf.MaxOperatingRecordNum)
                    }
                },
                SetInputQuantity: function (err, data) {
                    var currSelf = this;
                    if (!err && data && data.IsSuccess) {
                        currSelf.FormData.InputQty = data.Data;//投入数量
                    }
                },
                //渲染页面数据
                SetBaseData: function (retData) {
                    var currSelf = this;
                    currSelf.FormData.ScheduleID = retData.Data.JGMES_PLAN_SCRW_ID;
                    currSelf.FormData.TaskCode = retData.Data.SCRW_RWDH;
                    currSelf.FormData.InvCode = retData.Data.SCRW_CPBH;
                    currSelf.FormData.InvName = retData.Data.SCRW_NAME;
                    currSelf.FormData.InvStd = retData.Data.SCRW_CPGG;
                    currSelf.FormData.LineCode = retData.Data.SCRW_CXBM;
                    currSelf.FormData.TaskQty = retData.Data.SCRW_PCSL;
                    currSelf.FormData.OrderCode = retData.Data.SCRW_DDHM;
                    currSelf.FormData.OrderNum = retData.Data.SCRW_DDSL;
                    currSelf.FormData.ProcessCode = retData.Data.SCRW_LCKH;

                    if (retData.Data.Detail) {
                        currSelf.FormData.InvSNRule = retData.Data.Detail.PRODUCTDATA_TMYZGZ;//获取验证规则
                    }
                    //获取当前用户当前产品的工序
                    var data = GetCurrentProcess(currSelf.FormData.InvCode);
                    if (data.IsSuccess && data.Data) {
                        currSelf.CurrProcessIndex = data.Data.GXGL_GXSXH;  //首工位为1,大于1显示投入数量
                        if (Utils.TabletsGlobalParam.IsOpenInputQtyTask) {
                            GetInputQuantity(currSelf.FormData.InvCode, currSelf.FormData.ScheduleID, currSelf.SetInputQuantity);

                            var ret1 = setInterval(function () {
                                GetInputQuantity(currSelf.FormData.InvCode, currSelf.FormData.ScheduleID, currSelf.SetInputQuantity);
                            }, Utils.TabletsGlobalParam.InputQtyTaskFrequency);
                        }
                    }
                },
                Enter: function (event) {
                    var currSelf = this;
                    if (event.which == 13) {
                        var barCode = currSelf.BarCode;
                        currSelf.BarCode = "";
                        currSelf.SearchBarCode(barCode);
                        if (currSelf.IsEmptyObj) {
                            currSelf.GetComponentsDate(barCode);
                        }
                        if (currSelf.IsOldComponent) {
                            if (currSelf.IsEmptyObj) {
                                currSelf.SaveData(barCode);
                            }
                        }
                    }
                },
                SearchBarCode: function (barCode) {
                    var currSelf = this;
                    var showMsg;
                    if (!barCode || barCode.length <= 0) {
                        showMsg = 'SN码不能为空';
                        $.toptip(showMsg, "warning");
                        currSelf.SetOperateRecord(showMsg, false);
                        AudioUtils.Play(AudioUtils.ScanCodeFail);
                    } else {
                        currSelf.CurrBarCode = barCode;  //保存已输入的条码
                        $.showLoading();
                        $.ajax({
                            type: "post",
                            async: false,
                            url: LocalConfig.SrvPath + "/jgmes/commonAction!getCurrentProductByCxCp.action",
                            data: {
                                userCode: LocalUserInfo.GetUserInfo().UserCode,
                                mac: LocalUserInfo.GetUserInfo().Mac,
                                barCode: barCode,
                            },
                            dataType: "json",
                            success: function (ret) {
                                var retData = ReturnData(ret);
                                if (retData.IsSuccess) {
                                    for (var element in retData.Data) {
                                        currSelf.FormData.InvBarCode = barCode;
                                        currSelf.SetBaseData(retData);
                                        currSelf.IsEmptyObj = false;
                                        showMsg = '产品SN码扫描成功';
                                        $.toptip(showMsg, "success");
                                        currSelf.SetOperateRecord(showMsg, true);
                                        AudioUtils.Play(AudioUtils.ScanCodeSuccess);
                                        return false;//返回false，不为空对象
                                    }
                                    currSelf.IsEmptyObj = true;
                                    return true;//返回true，为空对象
                                }
                            }, error: function (xhr, status, errorThrown) {
                                console.log(xhr);
                                alert("请求失败");
                            }, complete: function () {
                                $.hideLoading();
                            }
                        });
                    }
                },
                GetComponentsDate: function (barCode) {
                    var currSelf = this;
                    var showMsg;
                    if (!currSelf.FormData.InvBarCode) {
                        showMsg = '产品SN码不能为空';
                        $.toptip(showMsg, "warning");
                        currSelf.SetOperateRecord(showMsg, false);
                        AudioUtils.Play(AudioUtils.ScanCodeFail);
                    } else {
                        $.showLoading();
                        $.ajax({
                            type: "post",
                            async: false,
                            url: LocalConfig.SrvPath + "/jgmes/finalQualityAssureanceAction!getOldCriticalComponent.action",//暂转移方法到finalQualityAssureanceAction中，原CommAction
                            data: {
                                userCode: LocalUserInfo.GetUserInfo().UserCode,
                                mac: LocalUserInfo.GetUserInfo().Mac,
                                rwNo: currSelf.FormData.TaskCode,
                                cpCode: currSelf.FormData.InvCode,
                                wlBarCode: barCode,
                            },
                            dataType: "json",
                            success: function (ret) {
                                var retData = ReturnData(ret);
                                if (retData.IsSuccess) {
                                    if (retData.Data != null) {
                                        currSelf.OddComponentBarcode = retData.Data.BGSJZB_TMH;
                                        currSelf.NewComponentRules = retData.Data.detail.PRODUCTDATA_TMYZGZ
                                        if (currSelf.ComponentBindData.length > 0 && (!currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].BindStatus)) {
                                            currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].InvCode = retData.Data.BGSJZB_WLBH;
                                            currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].InvName = retData.Data.BGSJZB_WLMC;
                                            currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].oldBarCode = retData.Data.BGSJZB_TMH;
                                        } else {
                                            currSelf.ComponentBindData.push({
                                                InvCode: retData.Data.BGSJZB_WLBH,
                                                InvName: retData.Data.BGSJZB_WLMC,
                                                oldBarCode: retData.Data.BGSJZB_TMH,
                                                newBarCode: "",
                                                BindStatus: false
                                            });
                                            // var record = {
                                            //     InvCode: retData.Data.BGSJZB_WLBH,
                                            //     InvName: retData.Data.BGSJZB_WLMC,
                                            //     oldBarCode: retData.Data.BGSJZB_TMH,
                                            //     newBarCode: "",
                                            //     BindStatus: false
                                            // };
                                            // currSelf.ComponentBindData.splice(0, 0, record);
                                        }
                                        currSelf.bgsjzbId = retData.Data.JGMES_PB_BGSJZB_ID;
                                        currSelf.IsOldComponent = false;
                                        return false;//返回false，不为空对象
                                    } else {
                                        if (currSelf.NewComponentRules && currSelf.ComponentBindData.length > 0 && (!currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].BindStatus)) {
                                            currSelf.IsOldComponent = true;
                                        }
                                        else {
                                            showMsg = '物料更换，请先扫描旧物料条码号！';
                                            $.toptip(showMsg, "warning");
                                            currSelf.SetOperateRecord(showMsg, false);
                                            AudioUtils.Play(AudioUtils.ScanCodeFail);
                                            currSelf.IsOldComponent = false;
                                        }
                                        return true;//返回true，为空对象
                                    }
                                }
                            }, error: function (xhr, status, errorThrown) {
                                console.log(xhr);
                                alert("请求失败");
                            }, complete: function () {
                                $.hideLoading();
                            }
                        });
                    }
                },
                SaveData: function (barCode) {
                    var currSelf = this;
                    var showMsg;
                    if (!currSelf.FormData.InvBarCode) {
                        showMsg = '产品SN码不能为空';
                        $.toptip(showMsg, "warning");
                        currSelf.SetOperateRecord(showMsg, false);
                        AudioUtils.Play(AudioUtils.ScanCodeFail);
                    } else {
                        if (Utils.IsTest(currSelf.NewComponentRules, barCode)) {
                            bootbox.confirm({
                                message: "是否进行关键物料更换？", buttons: {
                                    confirm: {
                                        label: '是',
                                        className: 'btn-success'
                                    },
                                    cancel: {
                                        label: '否',
                                        className: 'btn-danger'
                                    }
                                }, callback: function (result) {
                                    if (result) {
                                        $.showLoading();
                                        $.ajax({
                                            type: "post",
                                            async: false,
                                            url: LocalConfig.SrvPath + "/jgmes/finalQualityAssureanceAction!doSaveCriticalComponent.action",
                                            data: {
                                                userCode: LocalUserInfo.GetUserInfo().UserCode,
                                                mac: LocalUserInfo.GetUserInfo().Mac,
                                                cpCode: currSelf.FormData.InvCode,
                                                barCode: currSelf.FormData.InvBarCode,
                                                bgsjzbId: currSelf.bgsjzbId,
                                                newWlBarCode: barCode,
                                                oldWlBarCode: currSelf.OddComponentBarcode,
                                            },
                                            dataType: "json",
                                            success: function (ret) {
                                                var retData = ReturnData(ret);
                                                if (retData.IsSuccess) {
                                                    currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].newBarCode = barCode;
                                                    currSelf.ComponentBindData[currSelf.ComponentBindData.length - 1].BindStatus = true;
                                                    showMsg = '关键物料更换成功';
                                                    $.toptip(showMsg, "success");
                                                    currSelf.SetOperateRecord(showMsg, true);
                                                    AudioUtils.Play(AudioUtils.ScanCodeSuccess);
                                                } else {
                                                    AudioUtils.Play(AudioUtils.ScanCodeFail);
                                                    currSelf.SetOperateRecord(retData.message, false);
                                                }
                                            }, error: function (xhr, status, errorThrown) {
                                                console.log(xhr);
                                                alert("请求失败");
                                            }, complete: function () {
                                                $.hideLoading();
                                            }
                                        });
                                    }
                                }
                            });
                        } else {
                            showMsg = '新物料码和旧物料码不是同类型物料！';
                            $.toptip(showMsg, "error");
                            currSelf.SetOperateRecord(showMsg, false);
                            AudioUtils.Play(AudioUtils.ScanCodeFail);
                        }
                    }
                },
                SSNProcess: function () { //SSN码校验
                    var currSelf = this;
                    //0004VG-0001001AJ
                    var SNNCode = currSelf.CurrBarCode.substring(7, 14);
                    if (currSelf.FormData.InvBarCode.indexOf(SNNCode) >= 0)
                        return true;
                    else return false;
                }
            }
        });
    </script>
</body>

</html>